03. Extending your Robot Creation - Launch Files

Building Launch Files

You now know what needs to be done to upgrade your robot, so now it's time to turn our attention to the launch files for the project. There are infinitely many ways to set up your launch files. You could even go as far as having a single launch file for everything. However, this isn't advised, as there is a benefit to being able to launch each launch file in a dedicated terminal. Having each launch file in it's own respective terminal can serve important purposes for interaction and information visualization.

In this project, you are required to create all of the necessary launch files. You have the resources to generate all of them except a mapping.launch file. We will walk through the creation of that file, but we expect you to assemble the rest to complete the project. Before we get to the mapping.launch file, let’s take a look at the ideal executable steps for this project to see what’s going on.

1) Launch the gazebo world and your robot.

Example: $ roslaunch slam_project world.launch world_file:=~/catkin_ws/src/slam_project/worlds/kitchen_dining.world

2) Launch your teleop node.

Example: roslaunch slam_project teleop.launch

Note: Here would be a good place to pause and check that the robot moves with telop and is publishing the relevant topics. If not, we will be covering debugging shortly!

3) Launch your mapping node.

Example: roslaunch slam_project mapping.launch

4) Launch Rviz.

Example: $ roslaunch slam_project rviz.launch

A lot of these steps will seem familiar to you because you’ve seen them before in your last project. The new additions are:

  • Launching your own teleop node
  • Launching the mapping node

Your mapping launch file acts as the main node that interfaces with all the required parts to be able to perform SLAM with RTAB-Map. A labeled template for the mapping.launch file has been provided for you to use. Read through the code and the comments to understand what each part is accomplishing and why. Feel free to reach beyond this template with the resources linked below. Please note, that this template is sufficient in structure to complete the project!

<?xml version="1.0" encoding="UTF-8"?>

<launch>
  <!-- Arguments for launch file with defaults provided -->
  <arg name="database_path"     default="rtabmap.db"/>
  <arg name="rgb_topic"   default="/camera/rgb/image_raw"/>
  <arg name="depth_topic" default="/camera/depth/image_raw"/>
  <arg name="camera_info_topic" default="/camera/rgb/camera_info"/>  


  <!-- Mapping Node -->
  <group ns="rtabmap">
    <node name="rtabmap" pkg="rtabmap_ros" type="rtabmap" output="screen" args="--delete_db_on_start">

      <!-- Basic RTAB-Map Parameters -->
      <param name="database_path"       type="string" value="$(arg database_path)"/>
      <param name="frame_id"            type="string" value="base_footprint"/>
      <param name="odom_frame_id"       type="string" value="odom"/>
      <param name="subscribe_depth"     type="bool"   value="true"/>
      <param name="subscribe_scan"      type="bool"   value="true"/>

      <!-- RTAB-Map Inputs -->
      <remap from="scan"            to="/scan"/>
      <remap from="rgb/image"       to="$(arg rgb_topic)"/>
        <remap from="depth/image"     to="$(arg depth_topic)"/>
        <remap from="rgb/camera_info" to="$(arg camera_info_topic)"/>

        <!-- RTAB-Map Output -->
        <remap from="grid_map" to="/map"/>

           <!-- Rate (Hz) at which new nodes are added to map -->
      <param name="Rtabmap/DetectionRate" type="string" value="1"/> 

      <!-- 2D SLAM -->
      <param name="Reg/Force3DoF" type="string" value="true"/>    

      <!-- Loop Closure Detection -->
 <!-- 0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK 8=GFTT/ORB                 9=KAZE →
<param name="Kp/DetectorStrategy" type="string" value="0"/> 

<!-- Maximum visual words per image (bag-of-words) -->
          <param name="Kp/MaxFeatures" type="string" value="400"/>  

      <!-- Used to extract more or less SURF features -->
               <param name="SURF/HessianThreshold" type="string" value="100"/>

  <!-- Loop Closure Constraint -->
<!-- 0=Visual, 1=ICP (1 requires scan)-->
      <param name="Reg/Strategy" type="string" value="0"/> 

<!-- Minimum visual inliers to accept loop closure -->
      <param name="Vis/MinInliers" type="string" value="15"/> 

      <!-- Set to false to avoid saving data when robot is not moving -->
      <param name="Mem/NotLinkedNodesKept" type="string" value="false"/>

    </node> 
  </group>
</launch>

At this point, you could assemble your components to build your ROS package, but you may be met with difficulties in getting it to run. There may be a mis-named topic or an improper linkage. So what can we do? Well, like all good programmers we turn to debugging and that is what you will learn next!